#include <skyroad/cross_platform/console_ctrl.h>
#include <boost/thread/thread.hpp>


#ifdef _WIN32
BOOL WINAPI console_ctrl_handler(DWORD ctrl_type)
{
    switch (ctrl_type)
    {
    case CTRL_C_EVENT:
    case CTRL_BREAK_EVENT:
    case CTRL_CLOSE_EVENT:
    case CTRL_SHUTDOWN_EVENT:
        {
            TerminateProcess(GetCurrentProcess(), 1);
            return true;
        }
    default:
        return false;
    }
}

void set_console_ctr_handler()
{
    ::SetConsoleCtrlHandler(console_ctrl_handler, true);
}

void set_console_tilte(const char* title )
{
    ::SetConsoleTitle(title);
}

void get_ini_profile_str(const char *section,const char *key, char* buf,size_t length,const char *path)
{
    ::GetPrivateProfileString(section, key, "", buf, length, path);
}

void get_app_path(char* buffer,size_t length)
{
    ::GetModuleFileName(NULL, buffer, length);
}

#endif

void SKYROAD_DECL sleepex(int sec_time)
{
    boost::xtime xt;
    boost::xtime_get(&xt, boost::TIME_UTC_);
    xt.sec += sec_time;
    boost::thread::sleep(xt);
}


#ifdef _LINUX 
 /*
bool _stdcall console_ctrl_handler(int ctrl_type)
{
    switch (ctrl_type)
    {
    case CTRL_C_EVENT:
    case CTRL_BREAK_EVENT:
    case CTRL_CLOSE_EVENT:
    case CTRL_SHUTDOWN_EVENT:
        {
//            TerminateProcess(GetCurrentProcess(), 1);
            return true;
        }
    default:
        return false;
    }
}
void set_console_ctr_handler()
{
//    SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
}

void set_console_tilte(const char* title )
{
//    ::SetConsoleTitle(title);
}
*/
#endif
